package com.sgb.kjwl.startup;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.startup.Initializer;

import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.sgb.kjwl.api.UrlConfig;
import com.sgb.link.api.ErrorInterceptor;
import com.sgb.net.core.NetConfig;
import com.swgk.core.base.model.factory.PCCommonInterceptor;
import com.swgk.core.common.utils.CommonInitializer;
import com.swgk.core.base.model.factory.CookieInterceptor;
import com.swgk.core.customview.MyLoadFooter;
import com.swgk.core.customview.MyRefreshHeader;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: 杨畔
 * @date: 2021/2/24 09:35
 * @Description: 启动器，用于初始化三方库
 */
public class AppInitializer implements Initializer<Object> {

    @NonNull
    @Override
    public Object create(@NonNull Context context) {
        init();
        return null;
    }

    @NonNull
    @Override
    public List<Class<? extends Initializer<?>>> dependencies() {
        //添加依赖组件启动器
        List<Class<? extends Initializer<?>>> list = new ArrayList<>();
        list.add(CommonInitializer.class);
        return list;
    }

    /**
     * 初始化
     */
    private void init() {
        //添加刷新控件统一头部
        SmartRefreshLayout.setDefaultRefreshHeaderCreator((context, layout) -> new MyRefreshHeader(context));
        SmartRefreshLayout.setDefaultRefreshFooterCreator((context, layout) -> new MyLoadFooter(context));
        //配置网络请求
        NetConfig.config()
                .baseUrl(UrlConfig.NEW_BASE_URL)
                //token验证拦截器
                .addInterceptor(new CookieInterceptor());
        //新接口迁移登录失效拦截器
//                .addInterceptor(new ErrorInterceptor());
    }
}
